package com.xintai.approval.controller;

import java.util.List;

import com.xintai.approval.domain.FlowApply;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.approval.domain.FlowWorkflow;
import com.xintai.approval.service.IFlowWorkflowService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 工作流程Controller
 *
 * @author xintai
 * @date 2021-02-01
 */
@RestController
@RequestMapping("/approval/workflow")
public class FlowWorkflowController extends BaseController
{
    @Autowired
    private IFlowWorkflowService flowWorkflowService;

    /**
     * 查询工作流程列表
     */
    @PreAuthorize("@ss.hasPermi('approval:workflow:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowWorkflow flowWorkflow)
    {
        startPage();
        List<FlowWorkflow> list = flowWorkflowService.selectFlowWorkflowList(flowWorkflow);
        return getDataTable(list);
    }

    /**
     * 导出工作流程列表
     */
    @PreAuthorize("@ss.hasPermi('approval:workflow:export')")
    @Log(title = "工作流程", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FlowWorkflow flowWorkflow)
    {
        List<FlowWorkflow> list = flowWorkflowService.selectFlowWorkflowList(flowWorkflow);
        ExcelUtil<FlowWorkflow> util = new ExcelUtil<FlowWorkflow>(FlowWorkflow.class);
        return util.exportExcel(list, "workflow");
    }

    /**
     * 获取工作流程详细信息
     */
    @PreAuthorize("@ss.hasPermi('approval:workflow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(flowWorkflowService.selectFlowWorkflowById(id));
    }

    /**
     * 新增工作流程
     */
    @PreAuthorize("@ss.hasPermi('approval:workflow:add')")
    @Log(title = "工作流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowWorkflow flowWorkflow)
    {
        return toAjax(flowWorkflowService.insertFlowWorkflow(flowWorkflow));
    }

    /**
     * 修改工作流程
     */
    @PreAuthorize("@ss.hasPermi('approval:workflow:edit')")
    @Log(title = "工作流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowWorkflow flowWorkflow)
    {
        return toAjax(flowWorkflowService.updateFlowWorkflow(flowWorkflow));
    }

    /**
     * 删除工作流程
     */
    @PreAuthorize("@ss.hasPermi('approval:workflow:remove')")
    @Log(title = "工作流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(flowWorkflowService.deleteFlowWorkflowByIds(ids));
    }

    /**
     * 修改工作流程
     */
    @RequestMapping("/apply")
    public AjaxResult updateWorkFlowApply(@RequestBody FlowApply flowApply)
    {
        return toAjax(flowWorkflowService.updateWorkFlowApply(flowApply));
    }
}
